<?php
/**
 * Created by PhpStorm.
 * User: zsm
 * Date: 2018/5/11
 * Time: 13:31
 */

/**
 * 获取配置
 * @author zsm
 * @param null $name
 * @param null $val
 */
function Config($name = null, $val = null)
{
    static $_config = [];
    if (empty($name)) {
        return $_config;
    } elseif (is_string($name)) {
        if (empty($val)) {
            if (!strpos($name, '=>')) {
                return isset($_config[$name]) ? $_config[$name] : null;
            } else {
                $name = explode('=>', $name);
                return isset($_config[$name[0]][$name[1]]) ? $_config[$name[0]][$name[1]] : null;
            }
        } else {
            if (!strpos($name, '=>')) {
                //直接设置
                $_config[$name] = $val;
            } else {
                //设置二维
                $name = explode('=>', $name);
                $_config[$name[0]][$name[1]] = $val;
            }
        }
    } elseif (is_array($name)) {
        foreach ($name as $key => $value) {
            $_config[$key] = $value;
        }
        return;
    } else {
        return false;
    }
    return;
}

function dump($var, $echo = true, $label = null, $strict = true)
{
    $label = ($label === null) ? '' : rtrim($label) . ' ';
    if (!$strict) {
        if (ini_get('html_errors')) {
            $output = print_r($var, true);
            $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
        } else {
            $output = $label . print_r($var, true);
        }
    } else {
        ob_start();
        var_dump($var);
        $output = ob_get_clean();
        if (!extension_loaded('xdebug')) {
            $output = preg_replace('/\]\=\>\n(\s+)/m', '] => ', $output);
            $output = '<pre>' . $label . htmlspecialchars($output, ENT_QUOTES) . '</pre>';
        }
    }
    if ($echo) {
        echo($output);
        return null;
    } else
        return $output;
}